package com.hw01.controller;

import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import com.hw01.common.Result;
import com.hw01.common.ResultPage;
import com.hw01.dto.PayrollsQueryDto;
import com.hw01.service.PayrollsService;
import com.hw01.vo.PayrollsVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * 工资单管理
 **/
@RestController
@Api("工资单管理")
@RequestMapping("/payrolls")
public class PayrollsController {

    @Autowired
    private PayrollsService payrollsService;

    @GetMapping("/list")
    @ApiOperation("查询员工工资")
    public Result<List<PayrollsVo>> getPayrollsList(@ApiParam(value = "员工id", required = true) Long userId,
        @ApiParam("年份") String year, @ApiParam("月份") String month) {
        return payrollsService.getPayrollsList(userId, year, month);
    }

    @PostMapping("/page")
    @ApiOperation("查询员工工资单(分页)")
    @ResponseBody
    public ResultPage<PayrollsVo> getPayrollsPage(@RequestBody PayrollsQueryDto dto) {
        return payrollsService.getPayrollsPage(dto);
    }

    @GetMapping("/computation")
    @ApiOperation("一键评级-工资计算")
    public Result<Boolean> payrollComputation(@ApiParam("年份") String year, @ApiParam("月份") String month) {
        return payrollsService.payrollComputation(year, month);
    }

    @GetMapping("/download")
    @ApiOperation("下载工资单")
    public ResponseEntity<InputStreamResource> downloadPayrolls(@ApiParam("年份") String year, @ApiParam("月份") String month) {
        return payrollsService.downloadPayrolls(year, month);
    }

}
